/* eslint-disable import/no-anonymous-default-export */
import BIMApi from '@/services/bim'
import { v4 as uuidv4 } from 'uuid'

export default {
  state: {
    ifcId: ''
  },
  // eslint-disable-next-line no-unused-vars
  effects: dispatch => ({
    async getData(payload, { ifc }) {
      const { ifcId } = ifc
      if (!ifcId) return false
      const NKey = uuidv4()
      const title = '请求远程IFC数据'
      window.openNotification({ key: NKey, type: 'loading', title })
      const res = await BIMApi.getIfcData({ ifcId })
      if (res && res.res_code === 0) {
        window.openNotification({ key: NKey, type: 'success', title })
        return true
      } else {
        window.openNotification({ key: NKey, type: 'error', title })
        return false
      }
    }
  }),
  reducers: {
    update(prevState, payload) {
      return { ...prevState, ...payload }
    }
  }
}
